package AsLayers.Layer
{
	import AsLayers.BaseType.Bounds;
	import AsLayers.BaseType.Pixel;
	import AsLayers.Map;
	import AsLayers.Tile.ITile;
	import AsLayers.Tile.Image;
	
	import mx.containers.Canvas;
	
	public class WMS extends Grid
	{
		public var name:String
		public var url:String
		private var serviceUrl:String
		public  var container:Canvas=new Canvas();
		public var config:Object={
			 layers:""
		}
		public function WMS(name:String,url:String,config:Object)
		{
			super();
			this.name=name;
			this.url=url;
			this.config=config;
			this.serviceUrl=this.url+"?"+"LAYERS="+this.config.layers+"&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&FORMAT=image%2Fjpeg";
		}

		override public function setMap(map:Map):void{
			this.container.clipContent=false
			map.getLayerContainer().addChildAt(this.container,map.getLayerContainer().getChildren().length-1);
      
			super.setMap(map);
		//	trace(map.getLayerContainer().width)
			//this.container
			

		}
		override public function getUrl(bounds:Bounds):String{
			var w:Number=this.getTileSize().w;
			var h:Number=this.getTileSize().h;
			return this.serviceUrl+"&BBOX="+bounds.toBBOX()+"&WIDTH="+w+"&HEIGHT="+h;
		}
		override public function addTile(bounds:Bounds,position:Pixel):ITile{
			var tile:Image=new Image(position,bounds,this.getTileSize());
			tile.setLayer(this);
			this.container.addChild(tile.display);
			return tile;
		}
	}
}